package com.ruoyi.whzj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whzj.domain.WhTaskUser;
import com.ruoyi.whzj.service.IWhTaskUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户完成任务Controller
 * 
 * @author ruoyi
 * @date 2020-11-20
 */
@Controller
@RequestMapping("/whzj/taskuser")
public class WhTaskUserController extends BaseController
{
    private String prefix = "whzj/taskuser";

    @Autowired
    private IWhTaskUserService whTaskUserService;

    @RequiresPermissions("whzj:taskuser:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/taskuser";
    }

    /**
     * 查询用户完成任务列表
     */
    @RequiresPermissions("whzj:taskuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhTaskUser whTaskUser)
    {
        startPage();
        List<WhTaskUser> list = whTaskUserService.selectWhTaskUserList(whTaskUser);
        return getDataTable(list);
    }

    /**
     * 导出用户完成任务列表
     */
    @RequiresPermissions("whzj:taskuser:export")
    @Log(title = "用户完成任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhTaskUser whTaskUser)
    {
        List<WhTaskUser> list = whTaskUserService.selectWhTaskUserList(whTaskUser);
        ExcelUtil<WhTaskUser> util = new ExcelUtil<WhTaskUser>(WhTaskUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增用户完成任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户完成任务
     */
    @RequiresPermissions("whzj:taskuser:add")
    @Log(title = "用户完成任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhTaskUser whTaskUser)
    {
        return toAjax(whTaskUserService.insertWhTaskUser(whTaskUser));
    }

    /**
     * 修改用户完成任务
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WhTaskUser whTaskUser = whTaskUserService.selectWhTaskUserById(id);
        mmap.put("whTaskUser", whTaskUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户完成任务
     */
    @RequiresPermissions("whzj:taskuser:edit")
    @Log(title = "用户完成任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhTaskUser whTaskUser)
    {
        return toAjax(whTaskUserService.updateWhTaskUser(whTaskUser));
    }

    /**
     * 删除用户完成任务
     */
    @RequiresPermissions("whzj:taskuser:remove")
    @Log(title = "用户完成任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whTaskUserService.deleteWhTaskUserByIds(ids));
    }
}
